<style>
	.file_download{
		text-align: center;
		position: relative;
	}
	.file_download p {
		color: #FFF;
		position: absolute;
		top: 35px;
		left: 55px;
	}
	.btn_margin {
		margin-top: 20px;
	}
	.picter img{
		width: 80px;
		height: 80px;
	}
	.model_pic img {
		width: 100%;
		height: auto;
	}
</style>
<include file="Public/min-header"/>
<div class="wrapper">
  <include file="Public/breadcrumb"/>
    <section class="content">
    <div class="row">
      <div class="col-xs-12">
      	<div class="box">
        <!--新订单列表 基本信息-->
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title text-center">基本信息</h3>
            </div>
            <div class="panel-body">
               <table class="table table-bordered">
                    <tbody>
                    <tr>
                    	
                        <td>订单 ID:</td>
                        <td>订单号:</td>
                        <td>图号:</td>
                        <td>会员:</td>
						<td>电话:</td>
						<td>加工类型:</td>
						<td>产品名称:</td>
						<td>产品备注:</td>
						<td>产品数量:</td>
						<td>交货时间:</td>
                        <td>下单时间:</td>
                    </tr>
                    <tr>
                    	<foreach name="order" item="value" >
                    
                        <td>{$value.id}</td>
                        <td id="order_sn">{$value.order_sn}</td>
                        <td id="order_chartNumber">{$value.chart_number}</td>
                        <td>{$value.user_name}</td>
						<td>{$value.mobile}</td>
						<td style="color: #00A65A;">{$value.type}</td>
                     	<td>{$value.name}</td>
                     	<td>{$value.remark}</td>
                     	<td>{$value.product_quantity}</td>
                     	<td style="color: #3C8DBC;">{$value.time_delivery}</td>
                    	<td>{$value.dates}</td>
                    	</foreach>
                    </tr>

                    </tbody>
                </table>
            </div>
       </div>

        <!--客户上传文件处理-->
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title text-center">客户上传的文件</h3>
            </div>
            <div class="panel-body">
                <div class="row">
                	<foreach name="wenjian" item="value" >
                		<foreach name="value" item="v">
                		<div class="col-xs-2">
                		<div class="file_download">
                			<img src="/public/images/file_download.png"/>
                			<p>{$key}</p>
                		</div>
                		<div class="text-center btn_margin">
                			<!--<p>title.jpg</p>-->
                			<a class='btn btn-success btn-sm' href="{$v}" >下载文件</a>
                		</div>               		
                	</div>
                		</foreach>
                	</foreach>
                	<foreach name="tupian" item="value" >
                	<div class="col-xs-2">
                		
                		<div class="picter text-center">
                			<!--如果是 jpg png 就用自己-->
                			<img src="{$value}"/>
                		</div>
                		<div class="text-center btn_margin">
                			<a  class="btn btn-primary btn-sm" onclick=openNewWin("{$value}") >预览图片</a> 
                			<!--  图片不需要下载 -->
                			<!--<button class="btn btn-primary btn-sm" data-toggle="modal" data-target="#index{$key}">预览图片</button>          -->     		
                		</div>
                	</div>
                	
					</foreach>
                	
                </div>
            </div>
          </div>
          
          
          <!--分配工序-->
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title text-center">分配工序</h3>
            </div>
            <div class="panel-body">
                <div class="row">
                	<div class="col-xs-4 col-xs-offset-4">
                		<div class="text-center">
                			<form id="select_form" class="form-horizontal">
							  <div class="form-group">
							    <label for="gxxz" class="col-sm-3 control-label">工序选择</label>
							    <div class="col-sm-9">
							      <select name="gxsl" class="form-control" id="select_number">
							      	<option selected="selected">选择工序数量</option> 
							      </select>
							    </div>
							  </div>
							  <div class="auto_create">
							  	
							  </div>
							  
							  <input type="hidden" name="order_sn"/>
							  <input type="hidden" name="order_chartNumber" />
							</form>
							<button id="btn" class="btn btn-success" style="position: relative;left: 40px;" >确认提交</button>
                		</div>
                	</div>
                </div>
            </div>
       </div>
          
        </div>
	  </div>
    </div>
    
   <!-- 预览图片模态框 --> 
<foreach name="tupian" item="value" >

<div class="modal fade" id="index{$key}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel"></h4>
      </div>
      <div class="modal-body model_pic">
      	<!--这是预览图片 -->
        <img src="{$value}"/>
      </div>
    </div>
  </div>
</div>    
</foreach>    
   </section>
</div>

<!--错误提示框-->
<div class="modal fade bs-example-modal-sm" id="myModal_error" tabindex="-1">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-body">
      	  <h4 id="tips" class="text-center"></h4>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-danger btn-block" data-dismiss="modal">确认</button>
      </div>
    </div>
  </div>
</div>

<!--成功提示框-->
<div class="modal fade bs-example-modal-sm" id="myModal_success" tabindex="-1" data-backdrop="static" data-keyboard="false">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-body">
      	  <h4 class="text-center">操作成功</h4>
      </div>
      <div class="modal-footer">
        <!--<button id="confirm" type="button" class="btn btn-success btn-block" data-dismiss="modal">确认</button>-->
				<a href="http://www.jiejiangpt.com/index.php/Admin/Order/skip/order_sn/{$order[0]['order_sn']}" type="button" class="btn btn-success btn-block" >确认</a>
      
      </div>
    </div>
  </div>
</div>

</body>
<script>
function openNewWin(url)  
{  
    window.open(url);  
}  
//
// 选择工序数量
function gxsl(){
	for(var i = 1;i<=31;i++){
		$('#select_number').append("<option value='"+i+"'>"+i+"</option>");
	}
	
	// 自动生成select
	var keep = 0;
	$('#select_number').on('change',function(){
		var value = $(this).val();
		keep++;
		if(keep == 1){
			for(var i=1;i<=value;i++){
				// 拼接字符串
				var div = '<div class="form-group"><label for="inputEmail3" class="col-sm-3 control-label">工序'+i+'</label>\
								<div class="col-sm-9">\
									<select name="xzgx'+i+'" class="form-control select_gx">\
										<option selected="selected">选择工序</option>\
									</select>\
								</div>\
							</div>';
				$('.auto_create').append(div);
			}
		}else {
			// 第二次选择 先清理上一次记录
			$('.auto_create').children().remove();
			for(var i=1;i<=value;i++){
				var div = '<div class="form-group"><label for="inputEmail3" class="col-sm-3 control-label">工序'+i+'</label>\
								<div class="col-sm-9">\
									<select name="xzgx'+i+'" class="form-control select_gx">\
										<option selected="selected">选择工序</option>\
									</select>\
								</div>\
							</div>';
				$('.auto_create').append(div);
			}
		}
		
		var div = '\
			<option value="A_Tab_工序工序名称">A_Tab_工序工序名称</option><option value="B-清洗包装">B-清洗包装</option><option value="C-NC车">C-NC车</option>\
			<option value="C-NC立车">C-NC立车</option>\
			<option value="C-NC-立车-粗">C-NC-立车-粗</option>\
			<option value="C-普车">C-普车</option>\
			<option value="D-倒角打磨">D-倒角打磨</option>\
			<option value="D-字码刻印">D-字码刻印</option>\
			<option value="H-钣金焊接">H-钣金焊接 </option>\
			<option value="J-检验">J-检验</option>\
			<option value="J-三坐标">J-三坐标</option>\
			<option value="K-下料备料">K-下料备料</option>\
			<option value="M-平磨">M-平磨</option>\
			<option value="Q-气密试验">Q-气密试验</option>\
			<option value="W-表面处理">W-表面处理</option>\
			<option value="W-电火花线割">W-电火花线割</option>\
			<option value="W-激光割">W-激光割</option>\
			<option value="W-热处理">W-热处理</option>\
			<option value="W-外购">W-外购</option>\
			<option value="W-外协钣焊">W-外协钣焊</option>\
			<option value="W-外协机加">W-外协机加</option>\
			<option value="W-外协下料">W-外协下料</option>\
			<option value="X-NC立加">X-NC立加</option>\
			<option value="X-NC龙门铣">X-NC龙门铣</option>\
			<option value="X-NC卧加">X-NC卧加</option>\
			<option value="X-侧铣">X-侧铣</option>\
			<option value="X-大立铣">X-大立铣</option>\
			<option value="X-龙门铣">X-龙门铣</option>\
			<option value="X-普铣">X-普铣</option>\
			<option value="Y-液压校直">Y-液压校直</option>\
			<option value="Z-钳工钻攻">Z-钳工钻攻</option>\
		';
		$('.select_gx').append(div);
		
	})
}
gxsl();

$('#btn').on('click',function(){
	if($('#select_number').val() == '选择工序数量'){
		$('#myModal_error').modal('show');
		$('#tips').html('选择工序数量');
		return false;
	}else {		
		var result = true;
		var checkRepeat = [];
		$('.select_gx').each(function(i){
			
			if($(this).val() == '选择工序'){
				$('#myModal_error').modal('show');
				$('#tips').html('选择工序数量');
				return result = false;
			}else {
				checkRepeat.push($(this).val());
			}
		})
		function arrRepeat(arr){
		var arrStr = JSON.stringify(arr),str;
		for (var i = 0; i < arr.length; i++) {
		if (arrStr.indexOf(arr[i]) != arrStr.lastIndexOf(arr[i])){
		return true;
		}
		};
		return false;
		}
		
		if(result){
			var result = arrRepeat(checkRepeat);
			// 判断工序是否重复
			if(result == false){
				// 获取订单号 并 赋值给隐藏域
				var order_number = $('#order_sn').text();
				$('input[name=order_sn]').val(order_number);
				var chart_number = $('#order_chartNumber').text();
				$('input[name=order_chartNumber]').val(chart_number);
				$.ajax({
					type:"post",
					url:"/index.php/Admin/order/gxbc",
					data:$("#select_form").serializeArray(),
					success:function(data){
						$('#myModal_success').modal('show');
					},
					async:true
				});	

			}else {
				$('#myModal_error').modal('show');
				$('#tips').html('工序不能重复');
			}

		}else {
			$('#myModal_error').modal('show');
			$('#tips').html('请选择工序');
		}
	}
	
})
	
function pay_cancel(obj){
    var url =  $(obj).attr('data-url')+'/'+Math.random();
    layer.open({
        type: 2,
        title: '退款操作',
        shadeClose: true,
        shade: 0.8,
        area: ['45%', '50%'],
        content: url, 
    });
}
//取消付款
function pay_callback(s){
	if(s==1){
		layer.msg('操作成功', {icon: 1});
		layer.closeAll('iframe');
		location.href =	location.href;
	}else{
		layer.msg('操作失败', {icon: 3});
		layer.closeAll('iframe');
		location.href =	location.href;		
	}
}

// 弹出退换货商品
function selectGoods2(order_id){
	var url = "/index.php?m=Admin&c=Order&a=get_order_goods&order_id="+order_id;
	layer.open({
		type: 2,
		title: '选择商品',
		shadeClose: true,
		shade: 0.8,
		area: ['60%', '60%'],
		content: url, 
	});
}    
// 申请退换货
function call_back(order_id,goods_id)
{
	var url = "/index.php?m=Admin&c=Order&a=add_return_goods&order_id="+order_id+"&goods_id="+goods_id;	
	location.href = url;
}
</script>
</html>